$(function(){
	/*表单提交*/
	$(".btn").click(function(){
		var roleName  =	$("#name").val();;
		var status = $('input:radio[name="state"]:checked').attr("value");
		var memo = $("#textarea").val();
		var roleId = $("#roleId").val();
		var page = $("#page").val();
		var keywords = $("#keywords").val();
		if(roleName==''){
			show_err_msg('角色还没填呢！');
		}else if(/(\s)+/.test(roleName)){
            show_err_msg('输入的角色名不能包含空格!');
        }else{
			roleInsert(roleName,status,roleId,keywords,page,memo);
		}
	});
});
function roleInsert(roleName,status,roleId,keywords,page,memo){
	var xmlhttp;
    if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp = new XMLHttpRequest();
    }else {// code for IE6, IE5
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange = function () {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            var obj;
            try{
                obj =  eval('(' + xmlhttp.responseText + ')');
            }catch(exception){
                obj="error";
            }
            if(obj == "error"){
                show_err_msg("服务链接出错！");    
            }else{
                if(obj.status == "succeed")
					show_msg(obj.info,"/role/?keywords="+keywords+"&page="+page);
				else if(obj.status == "fail")
					show_err_msg(obj.info);
	            }
	        }
        }
    xmlhttp.open("POST", "/ajaxInsert/roleInsert/", true);
    xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlhttp.send("roleName="+roleName+"&memo="+memo+"&status="+status+"&roleId="+roleId);
}